import tkinter as tk
from tkinter import messagebox
import os
from pojo.page_manager import PageManager

def on_closing():
    """窗口关闭时的回调函数"""
    if messagebox.askokcancel("退出", "确定要退出程序吗?"):
        root.destroy()

if __name__ == "__main__":
    root = tk.Tk()
    root.title("我的工具箱")
    root.geometry("800x600")
    
    # 计算屏幕中心位置
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
    x = (screen_width - 800) // 2
    y = (screen_height - 600) // 2
    root.geometry(f"800x600+{x}+{y}")
    
    # 获取当前脚本所在目录，拼接图标路径
    base_dir = os.path.dirname(__file__)  # 当前文件所在目录
    icon_path = os.path.join(base_dir, "static", "favicon", "favicon.ico")

    # 设置窗口图标
    if os.path.exists(icon_path):
        root.iconbitmap(icon_path)
    else:
        print("Icon file not found at:", icon_path)

    # 创建页面管理器并初始化
    manager = PageManager(root)
    manager.init_pages()

    # 设置窗口关闭协议
    root.protocol("WM_DELETE_WINDOW", on_closing)

    root.mainloop()
